package com.example.backgroundmanger.controller;

import com.example.backgroundmanger.commons.Result;
import com.example.backgroundmanger.entity.Menu;
import com.example.backgroundmanger.entity.RoleMenu;
import com.example.backgroundmanger.service.IMenuService;
import com.example.backgroundmanger.service.IRoleMenuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 坤哥
 * @since 2024-07-06
 */
@RestController
@RequestMapping("/menu")
@Tag(name = "菜单模块")
public class MenuController {
    //注入业务层
    @Resource
    private IMenuService menuService;
    @Resource
    private IRoleMenuService roleMenuService;

    @Operation(summary = "获取菜单")
    @GetMapping("getMenus")
    public Result<List<Menu>> getMenus(){
        List<Menu> menus= menuService.getMenuService();
        return Result.success(menus);
    }

    @Operation(summary = "添加角色权限")
    @PostMapping("/saveRoleMenu")
    public Result<String> saveRoleMenu(@RequestBody RoleMenu roleMenu){
        roleMenuService.saveRoleMenuService(roleMenu);
        return Result.success("菜单权限设置成功!");
    }
}
